package com.freejava.test_swagger.api;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.HashMap;
import java.util.Map;

@Api("swagger GoldController of api")
public class GoldController {
    @ApiOperation(value = "获取最新的金价", notes = "获取当前金价")
    public String getGoldPrice() {
        return "237.58 RMB";
    }

    /**
     * 根据年份来获取当年年末的金价
     * @param year
     * @return
     */
    @ApiOperation(value = "根据年份来获取当年年末的金价", notes = "根据年份来获取当年年末的金价")
    public String getGoldPriceByYear(    @ApiParam(name = "YEAR", value = "查询年份", required = true)
                                             @PathVariable String year) {
        Map<String, String> goldWithYears = new HashMap<String, String>();
        goldWithYears.put("2015", "$1,060");
        goldWithYears.put("2016", "$1,151.70");
        goldWithYears.put("2017", "$1,296.50");
        for (String theYear : goldWithYears.keySet()) {
            if (theYear == year) {
                return goldWithYears.get(year);
            }
        }
        return "unknow";
    }
}
